﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Exepack;
using System.IO;
using System.Windows.Forms;

namespace ExepackTests
{
	/// <summary>
	/// Tests for CompressionOptionsView
	/// </summary>
	[TestClass]
	public class CompressionOptionsViewTest
	{
		public TestContext TestContext { get; set; }

		[TestMethod]
		public void CompressionOptionsView_NewlyCreatedOptionsAreNull()
		{
			using (var tv = new TreeView())
			{
				var v = new CompressionOptionsView(tv);
				Assert.IsNull(v.CompressionOptions);
			}
		}

		[TestMethod]
		public void CompressionOptionsView_AddingFileCreatesCompressionOptions()
		{
			string fileName = "Exepack.exe";
			Assert.IsTrue(File.Exists(fileName));

			using (var tv = new TreeView())
			{
				var v = new CompressionOptionsView(tv);
				v.Add(fileName);
				Assert.IsNotNull(v.CompressionOptions);
			}
		}

		[TestMethod]
		public void CompressionOptionsView_RootNodeIsCompressionOptions()
		{
			using (var tv = new TreeView())
			{
				var v = new CompressionOptionsView(tv);
				v.Add("Exepack.exe");
				Assert.IsTrue(v[tv.Nodes[0]] == v.CompressionOptions);
			}
		}

		[TestMethod]
		public void CompressionOptionsView_CheckRootNodeChildrenCount()
		{
			using (var tv = new TreeView())
			{
				var v = new CompressionOptionsView(tv);
				v.Add("Exepack.exe");
				Assert.IsTrue(tv.Nodes[0].Nodes.Count == v.CompressionOptions.AdditionalAssemblies.Count);
			}
		}

		[TestMethod]
		public void CompressionOptionsView_ClearTreeView()
		{
			using (var tv = new TreeView())
			{
				var v = new CompressionOptionsView(tv);
				v.Add("Exepack.exe");
				v.Clear();
				Assert.IsTrue(tv.Nodes.Count == 0);
			}
		}
	}
}
